// import com.alibaba.druid.sql.ast.SQLExprImpl;
// import com.alibaba.druid.sql.ast.SQLObject;
// import com.alibaba.druid.sql.ast.statement.SQLSelect;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

// import java.util.Collections;
// import java.util.List;

#include "OracleCursorExpr.h"
#include "../../../../ast/statement/SQLSelect.h"
#include "../../../../ast/SQLObject.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"

OracleCursorExpr::OracleCursorExpr()
{
}

SQLObject_ptr OracleCursorExpr::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleCursorExpr>(new OracleCursorExpr());
  std::shared_ptr<OracleCursorExpr> x = std::dynamic_pointer_cast<OracleCursorExpr>(clone_tmp);
  // OracleCursorExpr x = new OracleCursorExpr();
  if (query != nullptr)
  {
    x->setQuery(std::dynamic_pointer_cast<SQLSelect>(query->clone()));
  }
  return x;
}

OracleCursorExpr::OracleCursorExpr(SQLSelect_ptr query)
{
  setQuery(query);
}

SQLSelect_ptr OracleCursorExpr::getQuery()
{
  return query;
}

void OracleCursorExpr::setQuery(SQLSelect_ptr query)
{
  this->query = query;
}

// @Override
void OracleCursorExpr::accept0(SQLASTVisitor_ptr visitor)
{
  this->accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

void OracleCursorExpr::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleCursorExpr)))
  {
    acceptChild(visitor, query);
  }
  visitor->endVisit(SharedObject(OracleCursorExpr));
}

// @Override
SQLObject_list_ptr OracleCursorExpr::getChildren()
{
  SQLObject_list_ptr tmp = std::make_shared<std::list<SQLObject_ptr>>();
  tmp->push_back(this->query);
  return tmp;
}

// @Override
int OracleCursorExpr::hashCode()
{
  int prime = 31;
  int result = 1;
  result = prime * result + ((query == nullptr) ? 0 : query->hashCode());
  return result;
}

// @Override
bool OracleCursorExpr::equals(Object_ptr obj)
{
  if (this == obj.get())
  {
    return true;
  }
  if (obj == nullptr)
  {
    return false;
  }
  if (getClass()->c_str() != obj->getClass()->c_str())
  {
    return false;
  }
  OracleCursorExpr_ptr other = std::dynamic_pointer_cast<OracleCursorExpr>(obj);
  if (query == nullptr)
  {
    if (other->query != nullptr)
    {
      return false;
    }
  }
  else if (!query->equals(other->query))
  {
    return false;
  }
  return true;
}
